//
//  HomeWeiboModel.m
//  微blog
//
//  Created by Jorn.Wu on 15/8/24.
//  Copyright (c) 2015年 Jorn.Wu(jorn_wza@sina.com). All rights reserved.
//

#import "HomeWeiboModel.h"
#import "UserModel.h"
#import "RegexKitLite.h"
#import "NSString+Extension.h"

@implementation HomeWeiboModel

- (NSDictionary*)attributeMapDictionary{
    
    //   @"属性名": @"数据字典的key"
    NSDictionary *mapAtt = @{
                             @"createDate" : @"created_at",
                             @"weiboId" : @"id",
                             @"text" : @"text",
                             @"source" : @"source",
                             @"favorited" : @"favorited",
                             @"thumbnailImage" : @"thumbnail_pic",
                             @"bmiddlelImage" : @"bmiddle_pic",
                             @"originalImage" : @"original_pic",
                             @"geo" : @"geo",
                             @"repostsCount" : @"reposts_count",
                             @"commentsCount" : @"comments_count",
                             @"attitudes_count" : @"attitudes_count"
                             };
    
    return mapAtt;
}

- (void)setAttributes:(NSDictionary *)dataDic{
    
    [super setAttributes:dataDic];
    
    /**
     * 对来源文字解析
     */
    if (self.source != nil) {
        NSString *regex = @">.+<";  //>新浪 weibo.com<
        NSArray *items = [self.source componentsMatchedByRegex:regex];
        
        if (items.count != 0) {
            NSString *temp = items[0];      //其实只有一个
            temp = [temp substringWithRange:NSMakeRange(1, temp.length - 2)];
            self.source = [NSString stringWithFormat:@"来自:%@",temp];
        }
    }
    
    
    /**
     * 利用封装的扩展方法(将微博中表情文字转换文图标)
     */
    self.text = [NSString stringByEmotionRegexHandleFromString:self.text];
    
    
    /**
     * 解析用户信息
     */
    NSDictionary *userDic = [dataDic objectForKey:@"user"];
    if (userDic != nil) {
        
        UserModel *userModel = [[UserModel alloc] initWithDataDic:userDic];
        self.userModel = userModel;
        
    }
    
    NSDictionary *reDic = [dataDic objectForKey:@"retweeted_status"];
    if (reDic != nil) {
        
        self.srWeiboModel = [[HomeWeiboModel alloc] initWithDataDic:reDic];
    }
    
    
}

@end
